package com.jay.base.fileIO;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Created by caoyuan7 on 2020/1/6.
 */
public class CopyFile {
    public static void main(String args[]) throws IOException {
        FileReader fileReader = new FileReader("D:\\111.txt");
        FileWriter fileWriter = new FileWriter("D:\\222.txt");
        //method1(fileReader,fileWriter);
        method2(fileReader, fileWriter);

    }
    public static void method1(FileReader fileReader,FileWriter fileWriter) throws IOException {
        int ch;
        while ((ch=fileReader.read())!=-1){
            fileWriter.write(ch);
        }
        fileWriter.flush();
    }
    public static void method2(FileReader fileReader,FileWriter fileWriter) throws IOException {
        char chars[] = new char[1024];
        int ch=0;
        while ((ch =fileReader.read(chars))!=-1){
            System.out.println(ch);
            fileWriter.write(chars,0,ch);
        }
        fileWriter.flush();
    }
}
